package com.koron.common.core.interceptor.adapterImpl;

import com.koron.bean.enums.OperationMode;
import com.koron.common.core.config.ThreadLocalContext;
import com.koron.common.core.interceptor.FieldAdapter;
import org.springframework.stereotype.Component;

import java.lang.reflect.Field;

/**
 * @author jzp
 * @since 2021/9/27
 */
@Component
public class UpdateByAdapter implements FieldAdapter {

    @Override
    public void handler(Object parameter, Field field) throws IllegalAccessException {
        field.set(parameter, defaultValue());
    }

    @Override
    public Object defaultValue() {
        return ThreadLocalContext.getLoginUser().getAccount();
    }

    @Override
    public OperationMode getOperationMode() {
        return OperationMode.INSERT_UPDATE;
    }

    @Override
    public String[] fields() {
        return new String[]{"updateBy"};
    }
}
